//Kyle Marshall
//Assignment 4
//marshaky@onid.oregonstate.edu
//cs362

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>

//Adventure Embargo Card Random Test

int main (int argc, char** argv) {
  struct gameState G;
  int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
           sea_hag, tribute, smithy};
   int seed = 1000;
   int i, j, numPlayers, numTests, predrawntreasure,postdrawntreasure, currentPlayer;
   int prehandcount, posthandcount;
   int bonus = 0;
   numPlayers = 4;

   memset(&G, 23, sizeof(struct gameState)); 
   //can vary number of players
   initializeGame(numPlayers, k, seed, &G);

   /*Test to make sure that:
   	-if deckCount[currentPlayer] = 0, then shuffle.
   	-draw card is performed.
   	-top card of hand is most recently drawn card.
   	- if card drawn is a treasure card, drawntreasure increments
   	-if not a treasure, decrement handCount for that player(//this should just remove the top card (the most recently drawn one).)
   	- discard all cards in play that have been drawn

  */
  i = 0;
  numTests = 15;

  while(i < numTests){
  	G.whoseTurn = rand() % numPlayers;
  	currentPlayer = whoseTurn(&G);
  	
  	//test if treasurecount is incremented
	  	j=0;
	  	predrawntreasure = 0;
	  	while(G.hand[currentPlayer][j]){
	  		if(G.hand[currentPlayer][j] == 3 || G.hand[currentPlayer][j] == 4 || G.hand[currentPlayer][j] == 5){
	  			predrawntreasure++;
	  		}
	  		j++;
	  	}
	  	prehandcount = G.handCount[currentPlayer];

	  	cardEffect(adventurer, 1, 1, 1, &G, 1, &bonus);

	  	j=0;
	  	postdrawntreasure = 0;
	  	while(G.hand[currentPlayer][j]){
	  		if(G.hand[currentPlayer][j] == 3 || G.hand[currentPlayer][j] == 4 || G.hand[currentPlayer][j] == 5){
	  			postdrawntreasure++;
	  		}
	  		j++;
	  	}
	  	posthandcount = G.handCount[currentPlayer];

	  	if(predrawntreasure != postdrawntreasure){
	  		printf("Drawntreasure Test Passed\n");
	  	}else{
	  		if(prehandcount == (posthandcount -1)){
	  			printf("Drawntreasure Test Passed\n");
	  		}
	  		printf("Drawntreasure Test Failed\n");
	  		//exit(-1);
	  	}
  		
  	//test result of empty deck
  	if(i == (numTests -1)){
  		G.deckCount[currentPlayer] = 0;
  		cardEffect(adventurer, 1, 1, 1, &G, 1, &bonus);
  		if(G.deckCount[currentPlayer] > 0){
  			printf("Shuffle Test Passed!\n");
  		} else{
  			printf("Shuffle Test Failed\n");
  			//exit(-1);
  		}
  	}	

  	i++;
}

return 0;
}
